function addition(a: string, b: string) {
  if (!(isNaN(Number(a)) || isNaN(Number(b)))) {
    let [integera, decimala] = a.split(".");
    integera = integera || "";
    decimala = decimala || "0";
    let [integerb, decimalb] = b.split(".");
    integerb = integerb || "";
    decimalb = decimalb || "0";
    const lenIntegera: number = integera.length;
    const lenIntegerb: number = integerb.length;
    const lenDecimala: number = decimala.length;
    const lenDecimalb: number = decimalb.length;
    const integerMaxLen: number =
      Math.abs(lenIntegerb - lenIntegera) + lenIntegerb + 1;
    const decimalMaxLen: number = Math.max(lenDecimala, lenDecimalb);
    const integeraSpld = integera
      .padStart(integerMaxLen, "0")
      .split("")
      .map(Number);
    const integerbSpld = integerb
      .padStart(integerMaxLen, "0")
      .split("")
      .map(Number);
    const decimalaSpld = decimala
      .padEnd(decimalMaxLen, "0")
      .split("")
      .map(Number);
    const decimalbSpld = decimalb
      .padEnd(decimalMaxLen, "0")
      .split("")
      .map(Number);
    let integerRes = integeraSpld.map(() => 0);
    let decimalRes = decimalaSpld.map(() => 0);
    for (let i = decimalMaxLen - 1; i > -1; i--) {
      let n1 = Number(decimalaSpld[i]);
      let n2 = Number(decimalbSpld[i]);
      let rawRes = n1 + n2 + decimalRes[i];
      let subTenRes = rawRes - 10;
      if (subTenRes > 0) {
        i !== 0
          ? (decimalRes[i - 1] = subTenRes)
          : (integerRes[integerMaxLen - 1] = subTenRes);
      } else {
        decimalRes[i] = rawRes;
      }
    }
    for (let i = integerMaxLen - 1; i > -1; i--) {
      let n1 = Number(integeraSpld[i]);
      let n2 = Number(integerbSpld[i]);
      let rawAddRes = n1 + n2 + integerRes[i];
      let subTenRes = rawAddRes - 10;
      if (subTenRes > 0) {
        integerRes[i - 1] = subTenRes;
      } else {
        integerRes[i] = rawAddRes;
      }
    }
    while (integerRes[0] === 0 && integerRes.length !== 1) {
      integerRes.shift();
    }
    while (decimalRes[decimalRes.length - 1] === 0 && decimalRes.length !== 1) {
      decimalRes.pop();
    }
    return integerRes.join("") + "." + decimalRes.join("");
  } else {
    throw new Error("NaN");
  }
}

export default addition;
module.exports = addition;
